#!/usr/bin/env python
# -*- coding: utf-8 -*-
import cexapi
import datetime
import time
import re

credentialFile = open('credentials.txt', 'r+')

for line in credentialFile:
        resultLine = re.split(';', line)  
        if resultLine[0]=='hannesh':
            apiUser=resultLine[0]
            apiCred1=resultLine[1]
            apiCred2=resultLine[2]      

demo = cexapi.api(apiUser, apiCred1, apiCred2)

def balanceLTC():
    
   
    order_bookLTC = demo.order_book("LTC/BTC") 
    #print order_bookLTC
    #print order_bookLTC['bids']  
    ltc_bestBid=float(order_bookLTC['bids'][0][0])  
    ltc_bestAsk=float(order_bookLTC['asks'][0][0])
    
    #print "ltc bid",ltc_bestBid
    #print "ltc ask",ltc_bestAsk
   
    ltcBestBuyPrice=1/ltc_bestAsk
    ltcBestSellPrice=1/ltc_bestBid
    
    print "\nsell 1BTC for",ltcBestSellPrice, "LTC"
    print "buy  1BTC for",ltcBestBuyPrice, "LTC"


    

while True:    
    try: 
        balanceLTC()
        
        time.sleep(30)
    except:
        print "general Exception"
        time.sleep(60)
    